import {
  useCallback
} from 'react';
import {
  h0
} from './fp';

export default function useNav(departDate, dispatch, prevDate, nextDate) {
  // 出发日期早于今天不可点，前一天不可点
  const isPrevDisabled = h0(departDate) <= h0();
  // 到达日期在20天之后，下一天不可点
  const isNextDisabled = h0(departDate) - h0() > 20 * 86400 * 1000;

  const prev = useCallback(() => {
    if (isPrevDisabled) {
      return;
    }
    dispatch(prevDate());
  }, [isPrevDisabled]);

  const next = useCallback(() => {
    if (isNextDisabled) {
      return;
    }
    dispatch(nextDate());
  }, [isNextDisabled]);

  return {
    isPrevDisabled,
    isNextDisabled,
    prev,
    next,
  };
}